home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_1.arc / SPMTPL.C < prev    next >
Text File  |  1988-10-24  |  3KB  |  117 lines

  1. /* updated Oct. 18, 1988 to work with SDK 4.99 */
  2.  
  3. #define INCL_PM
  4. #include <os2.h>
  5. #include <stddef.h>
  6. #include <string.h>
  7.  
  8. #define EXTERN            /* all globals are declared in this module */
  9. #include "spmtpl.h"
  10.  
  11. /* local function declarations */
  12. void MainWndPaint(HWND hWnd, HPS hPS);
  13. BOOL WindowIsIconic(HWND hWnd);
  14.  
  15. /* entry point for program */
  16. int cdecl main(int argc, char *argv[])
  17. {
  18.  
  19.     QMSG qmsg;
  20.  
  21.   /* call initialization */
  22.     if (!InitProgram(argc, argv))
  23.     return FALSE;
  24.  
  25.   /* fall into message loop */
  26.     while (WinGetMsg(hAB, (PQMSG)&qmsg, (HWND)NULL, 0, 0))
  27.         WinDispatchMsg( hAB, (PQMSG)&qmsg );
  28.  
  29.   /* program exit */
  30.     WinDestroyWindow(hwndFrame);
  31.     WinDestroyMsgQueue(hmqMsgQ);
  32.     WinTerminate(hAB);
  33. }
  34.  
  35. /* main window message loop */
  36. MRESULT FAR PASCAL MainWndProc(HWND hWnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  37. {
  38.  
  39.     HPS hPS;        /* handle to PM display context */
  40.  
  41.     switch (msg) {
  42.  
  43.     case WM_CREATE:        /* called when main window is created */
  44.         WndCreate(hWnd);
  45.         break;
  46.  
  47.     case WM_CLOSE:        /* called when main window is closed */
  48.             WinPostMsg(hWnd, WM_QUIT, 0L, 0L) ;
  49.             break;
  50.  
  51.        case WM_PAINT:        /* called when window needs repainting */
  52.         hPS = WinBeginPaint(hWnd, (HPS)NULL, (PRECTL)NULL);
  53.         MainWndPaint(hWnd, hPS);
  54.         WinEndPaint( hPS );
  55.             break;
  56.  
  57.         case WM_ERASEBACKGROUND:    /* have PM take care of background */
  58.             return(TRUE);
  59.             break;
  60.  
  61.         default:        /* all other messages go here */
  62.             return( WinDefWindowProc( hWnd, msg, mp1, mp2 ) );
  63.             break;
  64.     }
  65.     return(0L);
  66. }
  67.  
  68. void MainWndPaint(HWND hWnd, HPS hPS)
  69. {
  70.  
  71.   /* Print a string in the icon area */
  72.  
  73. /* 
  74.   If Microsoft ever gets WinQueryWindowPos working correctly, then
  75.   replace the line 'if (WindowIsIconic(hWnd))' with the following: 
  76. */
  77. /*
  78.     SWP swp;
  79.  
  80.     WinQueryWindowPos(hWnd, &swp);
  81.  
  82.     if ((swp.fs & SWP_MINIMIZE) && (!(swp.fs & SWP_MAXIMIZE))) {
  83. */
  84.  
  85.     if (WindowIsIconic(hWnd)) {
  86.         POINTL pt;
  87.     pt.x = 0;
  88.       pt.y = 0;
  89.     GpiMove(hPS, (PPOINTL)&pt);
  90.     pt.x = xIconsize-1;
  91.     pt.y = yIconsize-1;
  92.         GpiBox(hPS, 2L, (PPOINTL)&pt, 0L, 0L);
  93.         pt.x = 0;
  94.         pt.y = 2 * (yIconsize - CharHeight) / 3;
  95.         GpiCharStringAt( hPS, (PPOINTL)&pt, (LONG)strlen(szIcon), (PCH)szIcon);
  96.     }
  97. }
  98.  
  99. /* 
  100.    Return TRUE if main window is iconic.
  101.    This kludge is needed since WinQueryWindowPos is not yet fully implemented.
  102. */
  103. BOOL WindowIsIconic(HWND hWnd)
  104. {
  105.  
  106.     RECTL cRect;
  107.  
  108.   /* get the current window client rectangle */
  109.     WinQueryWindowRect(hWnd, (PRECTL)&cRect);
  110.  
  111.   /* compare with size when window is iconic */
  112.     if ((cRect.xRight == xIconsize) && (cRect.yTop == yIconsize))
  113.     return TRUE;
  114.  
  115.     return FALSE;
  116. }
  117.